﻿--|--------------------------------------------------------------------------------
--| [AssignEntityToGame] - Update Procedure Script for Entity
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[AssignEntityToGame]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
	DROP PROCEDURE [dbo].[AssignEntityToGame]
GO

CREATE PROCEDURE [dbo].[AssignEntityToGame]
(
	@GameID int,
	@EntityID int,
	@ParentGameEntityID int,
	@GameRoleID int,
	@Visible bit,
	@OrderNumber int
)
AS
	SET NOCOUNT ON
	IF NOT EXISTS (SELECT * FROM dbo.[GameEntity] WHERE [GameID] = @GameID AND	[EntityID] = @EntityID)
		INSERT INTO GameEntity (GameID,EntityID,ParentGameEntityID,Visible,OrderNumber)
		VALUES (@GameID,@EntityID,@ParentGameEntityID, @Visible,@OrderNumber)
	ELSE
		UPDATE dbo.[GameEntity]
		SET 	ParentGameEntityID = @ParentGameEntityID,
			Visible = @Visible,
			OrderNumber = @OrderNumber,
			GameRoleID = @GameRoleID
		WHERE GameID = @GameID AND	EntityID = @EntityID 

	RETURN @@Error 
GO 